package com.ruihu.admin.module.business.tasknode.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruihu.admin.common.anno.MethodLog;
import com.ruihu.admin.common.domain.PageResultDTO;
import com.ruihu.admin.common.domain.ResponseDTO;
import com.ruihu.admin.module.business.tasknode.converter.TaskNodeFileList;
import com.ruihu.admin.module.business.tasknode.dao.TaskNodeFileDao;
import com.ruihu.admin.module.business.tasknode.domain.dto.*;
import com.ruihu.admin.module.business.tasknode.domain.entity.TaskNodeFileEntity;
import com.ruihu.admin.module.business.tasknode.domain.vo.TaskNodeFileVO;
import com.ruihu.admin.module.business.tasknode.domain.vo.TaskNodeFileExcelVO;
import com.ruihu.admin.module.business.tasknode.manager.TaskNodeFileManager;
import com.ruihu.admin.util.PageUtil;
import com.ruihu.admin.util.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * [ 任务环节附件表 ]
 *
 * @author Tony
 * @version 1.0
 * @company 瑞虎（南京）信息技术有限公司
 * @copyright (c)  瑞虎（南京）信息技术有限公司Inc. All rights reserved.
 * @date 2022-08-30 20:35:38
 * @since JDK1.8
 */
@Service
public class TaskNodeFileService {

    @Autowired
    private TaskNodeFileDao taskNodeFileDao;

    @Autowired
    private TaskNodeFileManager taskNodeFileManager;

    /**
     * 根据id查询
     */
    public TaskNodeFileEntity getById(Long id){
        return  taskNodeFileDao.selectById(id);
    }

    /**
     * 分页查询
     * @author Tony
     * @date 2022-08-30 20:35:38
     */
    @MethodLog
    public ResponseDTO<PageResultDTO<TaskNodeFileVO>> queryByPage(TaskNodeFileQueryDTO queryDTO) {
        Page page = PageUtil.convert2QueryPage(queryDTO);
        List<TaskNodeFileDTO> taskNodeFileDTOList = taskNodeFileDao.queryByPage(page, queryDTO);
        page.setRecords(TaskNodeFileList.convertDTOToTaskNodeFileVOList(taskNodeFileDTOList));
        PageResultDTO<TaskNodeFileVO> pageResultDTO = PageUtil.convert2PageResult(page);
        return ResponseDTO.succData(pageResultDTO);
    }

    /**
     * 添加
     * @author Tony
     * @date 2022-08-30 20:35:38
     */
    @MethodLog
    public ResponseDTO<String> add(TaskNodeFileAddDTO addDTO) {
        TaskNodeFileEntity entity = BeanUtil.copy(addDTO, TaskNodeFileEntity.class);
        taskNodeFileDao.insert(entity);
        return ResponseDTO.succ();
    }

    /**
     * 编辑
     * @author Tony
     * @date 2022-08-30 20:35:38
     */
    @MethodLog
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> update(TaskNodeFileUpdateDTO updateDTO) {
        TaskNodeFileEntity entity = BeanUtil.copy(updateDTO, TaskNodeFileEntity.class);
        taskNodeFileDao.updateByIdIgnoreEmptyValue(entity);
        return ResponseDTO.succ();
    }

    /**
     * 删除
     * @author Tony
     * @date 2022-08-30 20:35:38
     */
    @MethodLog
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> deleteFile(TaskNodeFileDeleteDTO taskNodeFileDeleteDTO) {
        return this.taskNodeFileManager.deleteTaskNodeFile(taskNodeFileDeleteDTO);
    }
}
